package com.gzq.common_core.base;

import android.text.TextUtils;

import com.gzq.common_core.base.config.CrashManagerConfig;
import com.gzq.common_core.base.config.GsonConfig;
import com.gzq.common_core.base.config.OkhttpConfig;
import com.gzq.common_core.base.config.RetrofitConfig;
import com.gzq.common_core.base.config.SessionManagerConfig;
import com.gzq.common_core.base.config.ToastConfig;

import me.jessyan.autosize.unit.Subunits;


public final class GlobalModel {
    private final ToastConfig toastConfig;
    private final String baseUrl;
    private final boolean isSupportDP;
    private final boolean isSupportSP;
    private final Subunits subunits;
    private final GsonConfig gsonConfig;
    private final OkhttpConfig okhttpConfig;
    private final RetrofitConfig retrofitConfig;
    private final SessionManagerConfig sessionManagerConfig;
    private final CrashManagerConfig crashManagerConfig;

    public String getBaseUrl() {
        return baseUrl;
    }

    public boolean isSupportDP() {
        return isSupportDP;
    }

    public boolean isSupportSP() {
        return isSupportSP;
    }

    public Subunits getSubunits() {
        return subunits;
    }

    public GsonConfig getGsonConfig() {
        return gsonConfig;
    }

    public OkhttpConfig getOkhttpConfig() {
        return okhttpConfig;
    }

    public RetrofitConfig getRetrofitConfig() {
        return retrofitConfig;
    }

    public SessionManagerConfig getSessionManagerConfig() {
        return sessionManagerConfig;
    }

    public CrashManagerConfig getCrashManagerConfig() {
        return crashManagerConfig;
    }

    public ToastConfig getToastConfig() {
        return toastConfig;
    }

    public GlobalModel(Builder builder) {
        this.baseUrl = builder.baseUrl;
        this.isSupportSP = builder.isSupportSP;
        this.isSupportDP = builder.isSupportDP;
        this.subunits = builder.subunits;
        this.gsonConfig = builder.gsonConfig;
        this.okhttpConfig = builder.okhttpConfig;
        this.retrofitConfig = builder.retrofitConfig;
        this.sessionManagerConfig = builder.sessionManagerConfig;
        this.crashManagerConfig = builder.crashManagerConfig;
        this.toastConfig = builder.toastConfig;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static final class Builder {
        private String baseUrl;
        private boolean isSupportDP;
        private boolean isSupportSP;
        private Subunits subunits;
        private GsonConfig gsonConfig;
        private OkhttpConfig okhttpConfig;
        private RetrofitConfig retrofitConfig;
        private SessionManagerConfig sessionManagerConfig;
        private CrashManagerConfig crashManagerConfig;
        private ToastConfig toastConfig;


        private Builder() {
        }

        public Builder baseurl(String baseUrl) {//基础url
            if (TextUtils.isEmpty(baseUrl)) {
                throw new IllegalArgumentException("BaseUrl can not be empty");
            }
            this.baseUrl = baseUrl;
            return this;
        }

        public Builder autoSize(boolean isSupportSP, boolean isSupportDP, Subunits subunits) {
            this.isSupportSP = isSupportSP;
            this.isSupportDP = isSupportDP;
            this.subunits = subunits;
            return this;
        }

        public Builder gsonConfiguration(GsonConfig gsonConfiguration) {
            this.gsonConfig = gsonConfiguration;
            return this;
        }

        public Builder okhttpConfiguration(OkhttpConfig okhttpConfiguration) {
            this.okhttpConfig = okhttpConfiguration;
            return this;
        }

        public Builder retrofitConfiguration(RetrofitConfig retrofitConfiguration) {
            this.retrofitConfig = retrofitConfiguration;
            return this;
        }

        public Builder sessionManagerConfiguration(SessionManagerConfig sessionManagerConfiguration) {
            this.sessionManagerConfig = sessionManagerConfiguration;
            return this;
        }

        public Builder crashManagerConfiguration(CrashManagerConfig crashManagerConfiguration) {
            this.crashManagerConfig = crashManagerConfiguration;
            return this;
        }

        public Builder toastStyle(ToastConfig toastConfig) {
            this.toastConfig = toastConfig;
            return this;
        }

        GlobalModel build() {
            return new GlobalModel(this);
        }
    }
}
